package cn.train.controler;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;



import cn.train.model.Admin;
import cn.train.service.AdminServices;

@WebServlet("/AddAdminServlet")
public class AddAdminServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
			String zt=req.getParameter("zhuangtai");
			String name=req.getParameter("name");
			String pass=req.getParameter("pass");
			int type=Integer.parseInt(zt);
			Admin ad=new Admin();
			ad.setAname(name);
			ad.setApass(pass);
			ad.setAdmtype(type);
			ad.setAstate(0);
			AdminServices adser=new AdminServices();
			resp.setContentType("text/html;charSet=utf-8");
			PrintWriter out =resp.getWriter();
			int m=adser.addAdmin(ad);
			if(m>0){
				out.print("<script>alert('添加成功');location.href='BackGuanliServlet'</script>");
			}
	}
	
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		
		doGet(req, resp);
	}
}
